
package ga;

import java.text.DecimalFormat;
import java.util.Map;


public class PickedSolution extends javax.swing.JFrame {
public String category;
public int k;
    /** Creates new form PickedSolution */
    public PickedSolution(String category) {
        initComponents();
        this.category=category;
        PrintPickedResults();
    }
    
 //<editor-fold defaultstate="collapsed" desc="Printing Results">
    public void PrintPickedResults(){
        
     for(k=0;k<MyProblem.RoundTimeSolution.size();k++){
               if(MyProblem.RoundTimeSolution.get(k).Round ==Integer.parseInt(category)){
                   SolutionText.setContentType("text/html");
                   SolutionText.setText(Print(Integer.parseInt(category),MyProblem.RoundTimeSolution.get(k).Final_Solution).toString());
                   this.setVisible(true);
               }
            }
            }
       public  StringBuilder Print(int j,Map <InitializeData.TVWS[], InitializeData.SecondarySystem> Solution ){
           StringBuilder Result=new StringBuilder();
           DecimalFormat df = new DecimalFormat("#.####");
           Result.append("<p>").append("Round: ").append(j).append("</p>");
           try { 
            if (Solution.isEmpty()) {
                Result.append("<p>No Solution</p>");
            } else {
                Result.append("<table><tr><td>System</td><td>Channels</td></tr>");
                for(Map.Entry<InitializeData.TVWS[], InitializeData.SecondarySystem> entry:Solution.entrySet()){
                    Result.append("<tr><td>").append(entry.getValue().name).append("   ").append("</td><td>");
                    int i=0;
                    for(InitializeData.TVWS channel:entry.getKey()){
                       if(i==entry.getValue().bandwidth){
                        Result.append(",");
                        Result.append("<font color='red'>").append("  ").append(channel.id).append(" subid  ").append(channel.subid).append(" (Guard Interval Channel) ").append("</font>");
                        break;
                       }
                        Result.append(",");
                        Result.append("  ").append(channel.id).append(" subid  ").append(channel.subid);
                        i++;        
                    }
                   
                }
                   Result.append("</td></tr></table>");
                   Result.append("fragmentation: ").append("<b>").append(MyProblem.RoundTimeSolution.get(k).Fragmentation).append("</b>").append(" ");
                   Result.append("Time elapsed: ").append("<b>").append(MyProblem.RoundTimeSolution.get(k).Elapsed_Time).append("</b>").append(" ");
            }
            
        
        } catch (Exception ex) {
         
        }    
           return Result;
       }
//</editor-fold>
       
 //<editor-fold defaultstate="collapsed" desc="Events">
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        SolutionText = new javax.swing.JEditorPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(700, 400));
        setResizable(false);

        jButton1.setText("Close");
        jButton1.setAlignmentX(0.5F);
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        SolutionText.setName("SolutionText"); // NOI18N
        jScrollPane1.setViewportView(SolutionText);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(190, 190, 190)
                .addComponent(jButton1)
                .addContainerGap(194, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(303, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(29, 29, 29))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(119, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        BarChart.p.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed
//</editor-fold>

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JEditorPane SolutionText;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
